'''
https://leetcode.cn/problems/kill-process
'''
from collections import defaultdict
from typing import List


class Solution:
    def killProcess(self, pid: List[int], ppid: List[int], kill: int) -> List[int]:
        graph = defaultdict(list)
        for pid, ppid in zip(pid, ppid):
            graph[ppid].append(pid)

        res = []
        def f(u):
            res.append(u)
            for v in graph[u]:
                f(v)
        f(kill)
        return res